import sys,os

if len(sys.argv)<2:
    print 'Usage: python extractPSL.py tableList'
    exit(1)

type=sys.argv[1].split('.')[0]
i=0
#colName=['chrom','chromStart','chromEnd','name','score','strand','thickStart','thickEnd','reserved','blockCount','blockSizes','chromStarts']
colName=['matches','misMatches','repMatches','nCount','qNumInsert','qBaseInsert','tNumInsert','tBaseInsert','strand','qName','qSize','qStart','qEnd','tName','tSize','tStart','tEnd','blockCount','blockSizes','qStarts','tStarts']
fi=open(sys.argv[1])
for line in fi:
    line=line.strip()
    if len(line)<1:
    	continue
    temp=line.split('\t')
    cmd='mysql -uroot hg19 -N -e \"select '+','.join(colName)+' from '+temp[0]+';\" >psl/'+temp[0]+'.psl'
    #print cmd
    os.system(cmd)
    #if i>5:
    #	break
fi.close()
